package com.hyz.login.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyz.login.mapper.ReportMapper;
import com.hyz.login.model.Report;
import com.hyz.login.service.ReportService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class ReportServiceImpl implements ReportService {

    @Resource
    private ReportMapper reportMapper;
    @Override
    public Integer reportPhone(String phone) {
        return reportMapper.reportPhone(phone);
    }

    @Override
    public Integer reportCarid(String carid) {
        return reportMapper.reportCarid(carid);
    }

    @Override
    public Integer reportAdd(Report report) {
        System.out.println(reportMapper.reportAdd(report));
        return reportMapper.reportAdd(report);
    }

    @Override
    public List<Report> findAll(String reportName,String time) {
        if (reportName==null){
            reportName="";
        }
        if (time==null || time == ""){
            time="1";
        }
        return reportMapper.findAll(reportName, Integer.valueOf(time));
    }

    @Override
    public IPage<Report> findPage(String reportName, Integer pageIndex, Integer size) {
        if (reportName==null){
            reportName="";
        }
        QueryWrapper<Report> wrapper = new QueryWrapper<Report>();
        wrapper.like("reportName",reportName);
        IPage<Report> iPage = new Page<Report>();
        iPage.setRecords(reportMapper.findPage(reportName, pageIndex-1, size));
        iPage.setTotal(reportMapper.selectCount(wrapper));
        iPage.setCurrent(pageIndex);
        iPage.setSize(size);


        return iPage;
    }

    @Override
    public String findZhuan(Integer reportId) {
        QueryWrapper<Report> wrapper = new QueryWrapper<Report>();
        wrapper.eq("reportId",reportId);
        Report  report = reportMapper.selectOne(wrapper);
        return report.getZhuan();
    }

    @Override
    public Integer modifyZhuanByReid(Integer reportId, String zhuan) {

        return reportMapper.modifyZhuanByReid(reportId, zhuan);
    }

    @Override
    public IPage<Report> findReg(Integer page, Integer limit) {
        QueryWrapper<Report> wrapper = new QueryWrapper<Report>();
        wrapper.like("state",4);
        IPage<Report> iPage = new Page<Report>();
        iPage.setRecords(reportMapper.findReg(page-1, limit));
        iPage.setTotal(reportMapper.selectCount(wrapper));
        iPage.setCurrent(page);
        iPage.setSize(limit);
        return iPage;
    }

    @Override
    public Integer modifyRegById(Integer reportId) {
        return reportMapper.modifyRegById(reportId);
    }
}
